home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / ULP5mos.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-09  |  5.0 KB  |  209 lines

  1.  
  2. #    r0        volatile, may be used by function linkage
  3. #    r1        stack pointer
  4. #    r2        table of contents register
  5. #    r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  6. #    r5  .. r10    volatile, pass 3rd - 8th int args
  7. #    r11        volatile, pass static chain if language needs it
  8. #    r12        volatile, used by dyn linker, exception handling
  9. #    r13 .. r31    saved
  10.  
  11.  
  12.  
  13. #    f0        volatile
  14. #    f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  15. #    f5  .. f13    volatile, pass 5th - 13th float args
  16. #    f14 .. f31    saved
  17.  
  18. #    Use r23    as CurCnt
  19. #    Use r24    as MaxCnt (Constant value)
  20. #    Use r25    as LPixelBuf
  21. #    Use r26    as location within ColorTable32
  22. #    Use r27    as base address of ColorTable32
  23. #    Use r28    as BPP (that is, bytes per pixel)
  24.  
  25. #    r29    as RightEdge
  26. #    r30    as xtemp (integer)
  27.  
  28.  
  29. #    Note that the following are constants, and independent of xtemp.
  30.  
  31. #    First the integers
  32. #    MaxCnt    in r24
  33. #    LPixelBuf in r25. It changes but need only be loaded 1 time.
  34. #    Base address of ColorTable32 in r27
  35. #    BPP in r28
  36.  
  37. #    Now the floats    (Newly defined)
  38.  
  39. #    3.00 in f14
  40. #    Zr in f15.  It changes as Zr is recalculated.
  41. #    Use f16    as value of yRel.  This is constant for each line.
  42. #    Use f17    Zi.  It's initially yRel, but changes within loop.
  43. #    Use f18    as xRel. Only changes as DX is added for the next pixel.
  44. #    Use f19 as |Z2| Only for comparing with Limit.
  45. #    Use f20    This is scratch and used shortly for 2Zi.
  46. #    Delta x    in f21
  47. #    Two    in f22
  48. #    Limit    in f23
  49. #    Use f24    as Zr2.  This is also a temporary value
  50. #    Use f26 as Zr3.
  51.  
  52.  
  53.     .text
  54.     .sdreg    13
  55.     .global    UseLibP5
  56.     .align    4
  57. UseLibP5:
  58.     mflr    11
  59.     stw    11,4(1)    #Save return address
  60.     stwu    1,-80(1)      #Save stack pointer
  61.     fmr    16,1        #Transfer yrel from f1 to f16
  62.     lis    4,MaxCnt@ha
  63.     lwz    24,MaxCnt@l(4)        #MaxCnt in r24.
  64.     lis    4,LPixelBuf@ha
  65.     lwz    25,LPixelBuf@l(4)    #Get Location of LPixelBuf
  66.     lis    4,ColorTable32@ha
  67.     lwz    27,ColorTable32@l(4)    #Start of color table
  68.  
  69.     lis    4,BPP@ha
  70.     lwz    28,BPP@l(4)             #Number bytes per pixel
  71.     lis    4,Factor@ha
  72.     lfd    25,Factor@l(4)    #Get Factor into f25
  73.     lis    4,Two@ha
  74.     lfd    22,Two@l(4)    #Get Two into f22 as constant
  75.     lis    4,Limit@ha
  76.     lfd    23,Limit@l(4)    #Get Limit into f23 as constant
  77.  
  78.     fadd    14,22,22    #f14 is 4.
  79.     fadd    14,14,22    #f14 is 6.
  80.     fdiv    14,14,22    #f14 is 3.
  81.  
  82. #The above could have been done with a global definition of 3.000.
  83.  
  84.     li    30,0        #xtemp = 0.
  85.     fsub    15,22,22    #(float)xtemp = 0.
  86.     lis    4,XCenter@ha
  87.     lfd    10,XCenter@l(4)    #f10 = XCenter
  88.     fsub    15,15,10    #xRel = xRel - XCenter
  89.     fdiv    18,15,25    #xRel = xRel/Factor
  90.  
  91.     lis    4,DX@ha
  92.     lfd    21,DX@l(4)    #Get the real value of Delta x.
  93.     lis    4,RightEdge@ha
  94.     lwz    29,RightEdge@l(4)
  95.  
  96. Start:
  97.     fmr    15,18        #Initial value of Zr is xRel
  98.  
  99. #  The following line was moved before rather than after fmr f17,f16
  100. #  to give the fpu a break.
  101.     li    23,1        #Initialize CurCnt = 1
  102.     fmr    17,16        #yRel into f17 as initial Zi.
  103.     b    l3        #Check to see if to MaxCnt
  104. l2:
  105.     fmul    24,15,15    #Zr2 in f24
  106.     fmul    4,17,17    #Zi2 = Zi*Zi
  107.     fadd    19,24,4    #Zr2 + Zi2 -> f19
  108.     fcmpu    0,19,23    #Compare with Limit in f23.
  109.     ble    0,l6
  110.  
  111. #The following section is not very time-critical as it is only reached once.
  112. #for each pixel
  113.     cmpwi    0,28,2    #See if BPP < 2
  114.     blt    0,l8
  115. l7:
  116.     slwi    10,23,2    #4 times CurCnt for offset in ColorTable32
  117.     add    26,27,10    #Find location of pixel color in ColorTable32
  118.     lwz    11,0(26)    #Get ARGB from ColorTable
  119.     stw    11,0(25)    #Store color in LPixelBuf
  120.     addi    25,25,4    #Point to next location in LPixelBuf
  121.     b    l1
  122.  
  123. l8:    andi.    3,23,65535    #Prep Color as UWORD for PlotIt
  124.     bl    PlotIt
  125. l9:    b    l1
  126. l6:
  127.  
  128.     fsub    27,24,4    #Zr2 - Zi2 -> f27
  129.     fmul    20,4,14    #Zi2*3 -> f20
  130.     fmul    28,24,14    #3*Zr2 -> f28
  131.     fsub    20,24,20    #Zr2 - 3*Zi2 -> f20
  132.  
  133.     fsub    28,4,28    #Zi2 - 3*Zr2 -> f28
  134.  
  135.     fmul    29,28,15    #Zr*(Zi2 - 3Zr2) -> f29
  136.     fmul    30,27,20    #(Zr2 - 3Zi2)*(Zr2 - Zi2) -> f30
  137.     fmul    29,29,4    #Zi2*Zr*(Zi2 - 3Zr2) -> f29
  138.     fmul    30,30,15    #Zr*(Zr2 - Z3*Zi2)*(Zr2 - Zi2) -> f30
  139.     fmul    29,29,22    #2*Zi2*Zr(Zi2 - 3Zr2) -> f29
  140.  
  141.     fmul    31,28,27    #(Zi2 - 3Zr2)(Zr2 - Zi2) -> f31
  142.     fadd    30,30,29    #Zr3 -> f30
  143.  
  144.     fmul    29,20,24    #Zr2*(Zr2 - 3Zi2) -> f29
  145.     fmul    31,31,17    #Times Zi
  146.     fmul    29,29,17    #Zi*Zr2*(Zr2 - 3Zi2) -> f29
  147.  
  148.     fadd    15,18,30    #New Zr = xRel + Zr2
  149.  
  150.     fmul    29,29,22    #times 2.0 -> f29
  151.  
  152.     fsub    17,29,31    #New Zi
  153. #    fmr    24,30       #New Zr
  154.  
  155.  
  156.  
  157.  
  158.     addi    23,23,1    #Increment CurCnt
  159.     fadd    17,16,17    #Zi = Zi + yRel
  160.  
  161. l3:
  162.     cmpw    0,23,24    #See if CurCnt < MaxCnt
  163.     blt    0,l2        #Repeat until MaxCnt reached
  164.  
  165.     cmpwi    0,28,2    #See if BPP < 2
  166.     blt    0,l11
  167. l10:
  168.  
  169.     lis    12,4
  170.     addi    12,12,-4
  171.     add    26,27,12    #Find location of pixel color
  172.     lwz    11,0(26)      #Get color
  173.  
  174.     stw    11,0(25)    #Store color in LPixelBuf
  175.     addi    25,25,4    #Point to next pixel in buffer
  176.     b    l1        #Was l12
  177. l11:
  178.     lis    11,1
  179.     addi    3,11,-1    #ffff for PlotIt
  180.     bl    PlotIt
  181. l1:
  182.     fadd    18,18,21    #Find new value of xRel (xRel = xRel + DX).
  183.     addi    30,30,1    #Increment xtemp.
  184.     cmpw    0,30,29    #See if to RightEdge
  185.  
  186.     blt    0,Start    #Repeat until row is done.
  187.     lis    4,LPixelBuf@ha
  188.     stw    25,LPixelBuf@l(4)  #New location in long pixel buffer
  189.     addi    1,1,80        #Balance Stack pointer
  190.     lwz    11,4(1)    #Get return address
  191.     mtlr    11
  192.  
  193.     blr
  194.     .type    UseLibP5,@function
  195.     .size    UseLibP5,$-UseLibP5
  196.  
  197.     .globl    MaxCnt
  198.     .globl    RightEdge
  199.     .globl    XCenter
  200.     .globl    Factor
  201.     .globl    Limit
  202.     .globl    Two
  203.     .globl    LPixelBuf
  204.     .globl    ColorTable32
  205.     .globl    BPP
  206.     .globl    DX
  207.     .globl    PlotIt
  208.  
  209.